import { createGlobalState } from '@vueuse/core'
import { ref } from 'vue'
import setting from '@/setting'
// 默认的系统设置
const setData = {
  // 默认主题
  defaultThemes: setting.theme.list.find((theme) => theme.fixed === true),
  // 默认本地化语言，默认中文
  defaultLocal: 'zh',
  // 是否显示标签栏，默认显示
  defaultShowTagBar: true,
  // 是否显示Logo，默认显示
  defaultShowLogo: true,
  // 是否显示加载动画，默认不显示
  defaultShowLoading: false
}
export const useSettingStore = createGlobalState(() => {
  const theme = ref(setData.defaultThemes)
  const local = ref(setData.defaultLocal)
  const showLogo = ref(setData.defaultShowLogo)
  const showTagBar = ref(setData.defaultShowTagBar)
  const showLoading = ref(setData.defaultShowLoading)

  // 设置主题颜色
  // const themeSet = (type: string) => {
  //   theme.value = setting.theme?.list?.find((theme) => theme.name === type) ?? {
  //     name: '金色沙滩',
  //     //默认主题
  //     fixed: true,
  //     value: {
  //       primaryColor: '#d2b48c',
  //       errorColor: '#c98a7d',
  //       warningColor: '#e2b14c',
  //       successColor: '#80b178',
  //       infoColor: '#d8c49a'
  //     }
  //   }
  // }

  // 设置主题颜色
  const themeSet = (type: string) => {
    theme.value = setting.theme.list.find((theme) => theme.name === type)
  }

  // 设置本地化语言
  const localSet = (type: string) => {
    local.value = type
  }

  // 设置显示标签栏
  const showLogoSet = (value: boolean) => {
    showLogo.value = value
  }

  // 设置显示Logo
  const showTagBarSet = (value: boolean) => {
    showTagBar.value = value
  }

  // 显示加载动画
  const showLoadingSet = (value: boolean) => {
    showLoading.value = value
  }

  return {
    theme,
    local,
    showLogo,
    showTagBar,
    showLoading,
    themeSet,
    localSet,
    showLogoSet,
    showTagBarSet,
    showLoadingSet
  }
})
